package com.ygqh.baby.service.wdtqyb.api;

import com.ygqh.baby.service.BaseApi;
import com.ygqh.baby.service.wdtqyb.http.WdtRequestExecutor;
import com.ygqh.baby.service.wdtqyb.util.WDTConfigure;
import com.ygqh.baby.utils.MD5;
import com.ygqh.baby.utils.MapUtil;

import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

/**
 */
public class MpApi extends BaseApi {

    private final static ResourceBundle WDT_QYB_BUNDLE;

    protected final WdtRequestExecutor wdtRequestExecutor;

    static {
        WDT_QYB_BUNDLE = ResourceBundle.getBundle("prop/wdt");
    }

    public MpApi() {
        super();
        this.wdtRequestExecutor = new WdtRequestExecutor();
    }

    public String getSign(Map<String, String> signParam) {
        String joinStr = MapUtil.toJoinStrHasSize(signParam, false, false);
        logger.info("wdt sign str: " + joinStr);
        String result = MD5.MD5Encode(joinStr.concat(getRequestUri(WDTConfigure.APP_SECRET))).toLowerCase();
        return result;
    }

    /**
     * 获取时间戳
     *
     * @return
     */
    public String getTimeStamp() {
        return String.valueOf(System.currentTimeMillis() / 1000);
    }

    public Map<String, String> getApplicationParam() {
        Map<String, String> map = new HashMap<String, String>();
        map.put("sid", getRequestUri(WDTConfigure.SID));
        map.put("appkey", getRequestUri(WDTConfigure.APP_KEY));
        map.put("timestamp", getTimeStamp());
        return map;
    }

    @Override
    protected ResourceBundle bundle() {
        return WDT_QYB_BUNDLE;
    }
}
